package com.neusoft.elm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.neusoft.elm.dao.AdminDao;
import com.neusoft.elm.po.Admin;
import com.neusoft.elm.util.DBUtil;



public class AdminDaoImpl implements AdminDao{
	Connection con = null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	
	public Admin getAdminByNameByPass(String adminName,String password){
//		TODO 
		String sql = "SELECT * FROM admin WHERE adminName = ? AND password = ? ";
		Admin admin = null;
		
		try {
//			
			con = DBUtil.getConnection();
//			
			pst = con.prepareStatement(sql);
			pst.setString(1, adminName);
			pst.setString(2, password);
//			
			rs = pst.executeQuery();
			
			while (rs.next()){
				admin = new Admin();
				admin.setAdminId(rs.getInt("adminId"));
				admin.setAdminName(rs.getString("adminName"));
				admin.setPassword(rs.getString("password"));
				
//				System.out.println(admin.getAdminName());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DBUtil.closeAll(rs, pst, con);
		}
		
		return admin;
	}
	
//	TODO 测试代码
//	public static void main(String[] args) {
//		new AdminDaoImpl().getAdminByNameByPass("王磊", "123");
//	}
}
